package com.tourism.controller;

import com.tourism.DTO.TourRouteDTO;
import com.tourism.common.Result;
import com.tourism.service.TourRouteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/admin/route")
@CrossOrigin
public class TourRouteController {

    @Autowired
    private TourRouteService tourRouteService;


    @PostMapping("/save")
    public Result saveRoute(@RequestBody TourRouteDTO routeDTO) {
        return tourRouteService.saveRoute(routeDTO);
    }

    @GetMapping("/{id}")
    public Result getRouteById(@PathVariable Integer id) {
        return tourRouteService.getRouteById(id);
    }


    @PutMapping("/update")
    public Result updateRoute(@RequestBody TourRouteDTO routeDTO) {
        return tourRouteService.updateRoute(routeDTO);
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteRoute(@PathVariable Integer id) {
        return tourRouteService.deleteRoute(id);
    }

    @GetMapping("/list")
    public Result getRouteList(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String routeName
    ) {
        return tourRouteService.getRouteList(current, size, routeName);
    }

}